﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace Simhopp.Common
{
    /// <summary>
    /// The network commands available.
    /// </summary>
    public enum Commands
    {
        NextRound,
        NextDiver,
        ScoreReceived,
        AddScore, 
        AddVerifiedScore,
        Login,
        LoginVerified,
        LoginFailed,
        Competition,
        Logout,
        BeginCompetition,
        AllCompetitions,
        SetCompetition
    }
    /// <summary>
    /// The NetworkCommand class provides a way of communication between the parties of the application.
    /// </summary>
    [Serializable]
    public class NetworkCommand : ISerializable
    {
        #region CONSTRUCTOR REGION
        /// <summary>
        /// Constructor taking arguments.
        /// </summary>
        /// <param name="com">The command to be sent with the network command package.</param>
        /// <param name="obj">The object to be sent with the network command package.</param>
        public NetworkCommand(Commands com, Object obj = null)
        {
            Command = com;
            Obj = obj != null ? obj : new Object();
        }
        #endregion
        #region PROPERTY REGION
        /// <summary>
        /// Gets the command part of the network command.
        /// </summary>
        public Commands Command { get; private set; }
        /// <summary>
        /// Gets the object sent with the network command.
        /// </summary>
        public Object Obj { get; private set; }
        #endregion
        #region SERIALIZE/DESERIALIZE REGION
        /// <summary>
        /// Adds the class specific information used in the serialization of an object.
        /// </summary>
        /// <param name="info">The class specific information.</param>
        /// <param name="context">Describes the source and destination of a given serialized stream.</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("command", Command, typeof(Commands));
            info.AddValue("object", Obj, Obj.GetType());
        }
        /// <summary>
        /// Constructor used in the deserialization of an object.
        /// </summary>
        /// <param name="info">The class specific information.</param>
        /// <param name="context">Describes the source and destination of a given serialized stream.</param>
        protected NetworkCommand(SerializationInfo info, StreamingContext context)
        {
            Command = (Commands)info.GetValue("command", typeof(Commands));
            Obj = (Object)info.GetValue("object", typeof(Object));
        }
        #endregion
    }
}
